const jwt = require('jsonwebtoken')

const whiteList = ['/login', '/signIn']

module.exports = options => {
    return async function auth(ctx, next) {
        if(whiteList.includes(ctx.path)){
            await next()
        }else{
            let token=ctx.request.header
            if(token){
                jwt.verify(token,'1906A')
                try{
                    await next()
                }catch(err){
                    ctx.body={
                        code:402,
                        mes:'token验证失败'
                    }
                }
            }else{
                ctx.body={
                    code:302,
                    mes:"没有token值"
                }
            }
        }
    };
};